package portal.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import portal.excepcion.DAOExcepcion;
import portal.modelo.Persona;
import portal.modelo.Usuario;
import portal.util.ConexionBD;

public class PersonaDAO extends BaseDAO {
	
public Boolean insertarNuevaPersona (Persona a, Usuario u) throws DAOExcepcion {
	
	boolean status = Boolean.TRUE;
	String query = "call INSERT_PERSONA_USUARIO(?,?,?,?,?,?,?,?,?,?,?)";
	Connection con = null;
	PreparedStatement stmt = null;
	ResultSet rs = null;
	
	try {
		con = ConexionBD.obtenerConexion();
		stmt = con.prepareStatement(query);
		stmt.setString(1, a.getNombresPersona());
		stmt.setString(2, a.getApellidoPaternoPersona());
		stmt.setString(3, a.getApellidoMaternoPersona());
		stmt.setString(4, a.getSexoPersona());
		stmt.setString(5, a.getCorreoPersona());
		stmt.setString(6, a.getNumeroDniPersona());
		stmt.setString(7, a.getNumeroCelularPersona());
		stmt.setString(8, a.getDireccionPersona());
		stmt.setString(9, a.getTipoDocumento_idTipoDocumento());
		stmt.setString(10, u.getLoginUsuario());
		stmt.setString(11, u.getPasswordUsuario());
		
		
		int i = stmt.executeUpdate();
		if (i != 1) {
			throw new SQLException("NO INSERTO");
		}
	} catch (SQLException e) {
		System.err.println(e.getMessage());
		throw new DAOExcepcion(e.getMessage());
	} finally {
		this.cerrarResultSet(rs);
		this.cerrarStatement(stmt);
		this.cerrarConexion(con);
	}
	
	return status;
}


	
}
